/**
 * 
 */
package com.ls.lserp.modules.sys.entity;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.ls.lserp.common.config.Global;
import com.ls.lserp.common.persistence.DataEntity;
import com.ls.lserp.common.utils.excel.annotation.ExcelField;

/**
 * 用户Entity
 * @author LiuPeng
 * @version 2013-12-05
 */
public class User extends DataEntity<User> {

	private static final long serialVersionUID = 1L;
	//姓
	private String firstName;
	//名
	private String lastName;
	// 登录名
	private String loginName;
	// 密码
	private String password;
	// 性别
	private String sex;
	//出生年月日
	private Date birthDate;
	//国家
	private String country;
	//城市
	private String city;
	//地址
	private String address;
	//电话
	private String telNo;
	//手机
	private String mobile;
	//邮箱
	private String email;
	//传真
	private String faxNo;
	//账户类型（1、平台账户；2、店铺账户；3、加工厂账户）
	private String userType;
	//邮件发送结果（0、发送成功； 1、发送失败）(重置密码用)
	private String mailsendFlag;
	//系统人员标识(0-公司操作人员 1-公司管理员 2-平台管理员<system用户专用>)
	private String adminFlag;
	//是否可以登录
	private String loginFlag;
	// 原登录名
	private String oldLoginName;
	// 新密码
    private String newPassword; 
    // 用户用户创建人
    private String userCreatUser;
    //最后一次登录IP
    private String loginIp;
    //最后一次登录日期
    private Date  lastDate;
    // 根据角色查询用户条件
    private Role role; 
    //店铺信息
    private Shop shop;
    // 邮件随机码（邮件验证链接唯一性识别用）
    private String emailRandomCode;
    // 邮件发送时间（邮件验证链接有效性判断用）
    private Date emailSendTime;
    // 拥有角色列表
	private List<Role> roleList = Lists.newArrayList(); 
	
	public User() {
        super();
        this.loginFlag = Global.YES;
    }
	
	public User(Long id){
        super(id);
    }

	public User(Long id, String loginName){
        super(id);
        this.loginName = loginName;
    }
	
	public User(Role role){
        super();
        this.role = role;
    }
    
	@JsonIgnore
    public List<Role> getRoleList() {
        return roleList;
    }
    
    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }
    
    @JsonIgnore
    public List<Long> getRoleIdList() {
        List<Long> roleIdList = Lists.newArrayList();
        for (Role role : roleList) {
            roleIdList.add(role.getId());
        }
        return roleIdList;
    }

    public void setRoleIdList(List<Long> roleIdList) {
        roleList = Lists.newArrayList();
        for (Long roleId : roleIdList) {
            Role role = new Role();
            role.setId(roleId);
            roleList.add(role);
        }
    }

    
    public boolean isAdmin(){
        return isAdmin(this.id);
    }
    
    public static boolean isAdmin(Long id){
        return id != null && id==1L;
    }
    
    @ExcelField(title="ID", type=1, align=2, sort=1)
    public Long getId() {
        return id;
    }
    
    @ExcelField(title="姓", type=1, align=2, sort=3)
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    @ExcelField(title="名", type=1, align=2, sort=2)
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getLoginName() {
        return loginName;
    }
    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @ExcelField(title="性别", type=1, align=2, sort=1)
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getTelNo() {
        return telNo;
    }
    public void setTelNo(String telNo) {
        this.telNo = telNo;
    }
    public String getMobile() {
        return mobile;
    }
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getFaxNo() {
        return faxNo;
    }
    public void setFaxNo(String faxNo) {
        this.faxNo = faxNo;
    }
    public String getUserType() {
        return userType;
    }
    public void setUserType(String userType) {
        this.userType = userType;
    }
    public String getMailsendFlag() {
        return mailsendFlag;
    }
    public void setMailsendFlag(String mailsendFlag) {
        this.mailsendFlag = mailsendFlag;
    }
    public String getAdminFlag() {
        return adminFlag;
    }
    public void setAdminFlag(String adminFlag) {
        this.adminFlag = adminFlag;
    }
    
    public String getLoginFlag() {
        return loginFlag;
    }

    public void setLoginFlag(String loginFlag) {
        this.loginFlag = loginFlag;
    }

    public String getOldLoginName() {
        return oldLoginName;
    }

    public void setOldLoginName(String oldLoginName) {
        this.oldLoginName = oldLoginName;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return id.toString();
    }

    public String getUserCreatUser() {
        return userCreatUser;
    }

    public void setUserCreatUser(String userCreatUser) {
        this.userCreatUser = userCreatUser;
    }
    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public Date getLastDate() {
        return lastDate;
    }

    public void setLastDate(Date lastDate) {
        this.lastDate = lastDate;
    }

    public Shop getShop() {
        return shop;
    }

    public void setShop(Shop shop) {
        this.shop = shop;
    }

	public String getEmailRandomCode() {
		return emailRandomCode;
	}

	public void setEmailRandomCode(String emailRandomCode) {
		this.emailRandomCode = emailRandomCode;
	}

	public Date getEmailSendTime() {
		return emailSendTime;
	}

	public void setEmailSendTime(Date emailSendTime) {
		this.emailSendTime = emailSendTime;
	}
    
	
}